var a = require("../../utils/api.js"), e = getApp();

Page({
    data: {
        info: "",
        nav: [ {
            title: "充值记录",
            op: "recharge"
        }, {
            title: "消费记录",
            op: "consumption"
        } ],
        open: 1,
        cur: 0,
        showLoding: !0
    },
    onLoad: function(a) {},
    onShow: function() {
        var t = this;
        t.setData({
            showLoding: !1
        }), a.markrting({
            op: "recharge",
            openid: e.globalData.openid
        }).then(function(a) {
            if (console.log(a), 0 == a.code) {
                for (var e = a.data.data.recharge && a.data.data.recharge.length >= 0 ? a.data.data.recharge : [], o = (a.data.data.consumption && a.data.data.consumption.length >= 0 && a.data.data.consumption, 
                0); o < e.length; o++) console.log(e[o].create_time), e[o].timeformat = t.timeformat(e[o].create_time, "M/D h:m");
                if (e.length < 10) var r = 0, n = !0; else r = 1;
                t.setData({
                    info: a.data.data,
                    detail: a.data.data.recharge,
                    type: "recharge",
                    page: r,
                    showLoding: !0,
                    showNomore: n
                });
            } else 1 == a.code && (wx.showToast({
                title: a.msg,
                icon: "none",
                duration: 2e3,
                mask: !0
            }), t.setData({
                showLoding: !0
            }));
        });
    },
    recharge: function() {
        wx.navigateTo({
            url: "/pages/member/overageRecharge"
        });
    },
    norecharge: function() {
        wx.showToast({
            title: "您的余额还在使用中",
            icon: "none",
            duration: 2e3
        });
    },
    changenav: function(t) {
        console.log(t);
        var o = this, r = t.currentTarget.dataset.ind, n = t.currentTarget.dataset.op;
        console.log(n), a.markrting({
            op: "recharge",
            openid: e.globalData.openid
        }).then(function(a) {
            if (console.log(a), "consumption" == n) {
                e = a.data.data.consumption && a.data.data.consumption.length > 0 ? a.data.data.consumption : [];
                console.log(e);
                for (t = 0; t < e.length; t++) e[t].timeformat = o.timeformat(e[t].gos_add_time, "M/D h:m");
            } else if ("recharge" == n) {
                var e = a.data.data.recharge && a.data.data.recharge.length > 0 ? a.data.data.recharge : [];
                console.log(e);
                for (var t = 0; t < e.length; t++) e[t].timeformat = o.timeformat(e[t].create_time, "M/D h:m");
            }
            0 == e.length && o.setData({
                showNomore: !0
            }), o.setData({
                cur: r,
                detail: e,
                type: n,
                page: e.length < 10 ? 0 : 1
            });
        });
    },
    timeformat: function(a, e) {
        var t = [ "Y", "M", "D", "h", "m", "s" ], o = [], r = parseInt(a), n = new Date(1e3 * r);
        o.push(n.getFullYear()), o.push(n.getMonth() + 1 >= 10 ? n.getMonth() + 1 : "0" + (n.getMonth() + 1)), 
        o.push(n.getDate() >= 10 ? n.getDate() : "0" + n.getDate()), o.push(n.getHours() >= 10 ? n.getHours() : "0" + n.getHours()), 
        o.push(n.getMinutes() >= 10 ? n.getMinutes() : "0" + n.getMinutes()), o.push(n.getSeconds() >= 10 ? n.getSeconds() : "0" + n.getSeconds());
        for (var g in o) e = e.replace(t[g], o[g]);
        return e;
    },
    onReachBottom: function(t) {
        var o = this;
        if ("consumption" == o.data.type) {
            if (0 == o.data.page) return o.setData({
                showNomore: !0
            }), !1;
            if (1 == o.data.page) r = {
                op: "recharge_flow",
                openid: e.globalData.openid,
                status: 2
            }; else r = {
                op: "recharge_flow",
                openid: e.globalData.openid,
                status: 2,
                page: o.data.page
            };
        }
        if ("recharge" == o.data.type) {
            if (0 == o.data.page) return o.setData({
                showNomore: !0
            }), !1;
            if (1 == o.data.page) r = {
                op: "recharge_flow",
                openid: e.globalData.openid,
                status: 1
            }; else var r = {
                op: "recharge_flow",
                openid: e.globalData.openid,
                status: 1,
                page: o.data.page
            };
        }
        a.markrting(r).then(function(a) {
            console.log(a);
            var e = o.data.detail;
            if ("consumption" == o.data.type) for (t = 0; t < a.data.data.recharge.length; t++) a.data.data.recharge[t].timeformat = o.timeformat(a.data.data.recharge[t].gos_add_time, "M/D h:m"), 
            e.push(a.data.data.recharge[t]); else for (var t = 0; t < a.data.data.recharge.length; t++) a.data.data.recharge[t].timeformat = o.timeformat(a.data.data.recharge[t].create_time, "M/D h:m"), 
            e.push(a.data.data.recharge[t]);
            if (a.data.data.recharge.length < 10) r = 0; else var r = o.data.page + 1;
            o.setData({
                detail: e,
                page: r
            });
        });
    }
});